﻿/*+===================================================================
File:      FlyItem.h

Summary:   Hiện thực hóa các phương thức của lớp FlyItem
===================================================================+*/

#include "FlyItemBound.h"
#include "PlayState.h"

CFlyItemBound::CFlyItemBound(CBill* pBill, D3DXVECTOR2 pos, int id, int typeId, int bulletType)
	:CMoveableObject(pos, id, typeId)
{
	CResourcesManager::GetInstance()->GetSprite(ID_SPRITE_FLY_ITEM);
	CResourcesManager::GetInstance()->GetSprite(ID_SPRITE_M_ITEM);
	CResourcesManager::GetInstance()->GetSprite(ID_SPRITE_B_ITEM);
	CResourcesManager::GetInstance()->GetSprite(ID_SPRITE_F_ITEM);
	CResourcesManager::GetInstance()->GetSprite(ID_SPRITE_S_ITEM);
	CResourcesManager::GetInstance()->GetSprite(ID_SPRITE_L_ITEM);
	CResourcesManager::GetInstance()->GetSprite(ID_SPRITE_R_ITEM);
	m_pBill = pBill;
	m_nBulletType = ID_M_ITEM + bulletType;
	m_pTextureBox = m_pResourceManager->GetTexture(ID_TEXTURE_GROUND_BOX);
	switch (g_nCurentLvl)
	{
	case ID_LEVEL1:
	case ID_LEVEL3:
		m_boxBorn =
		{
			m_pos.x + SCREEN_WIDTH / 2,
			SCREEN_HEIGHT,
			SCREEN_WIDTH / 2,
			SCREEN_HEIGHT,
			0.0f,
			0.0f
		};
		break;
	case ID_LEVEL2:
		m_boxBorn =
		{
			64,
			m_pos.y + SCREEN_HEIGHT,
			SCREEN_WIDTH,
			SCREEN_HEIGHT / 2,
			0.0f,
			0.0f
		};
		break;
	}
}

CFlyItemBound::~CFlyItemBound()
{
	if (m_pBill)
		delete m_pBill;
}
void CFlyItemBound::Update(float timeFrame)
{
	if (!m_bIsLive)
		return;
	if (m_pBill->GetBox().IsIntersect(m_boxBorn))
	{
		m_bIsFirstBorn = true;	
		CFlyItem* tmpObject = NULL;
		tmpObject = new CFlyItem(D3DXVECTOR2(m_pos.x, m_pos.y + 10.0f),
			m_nId, m_nTypeId, m_nBulletType);
		CPlayState::s_objsOutSideQuadTree.push_back(tmpObject);
		this->Kill();
	}
}

void CFlyItemBound::Draw()
{
	
}
void CFlyItemBound::UpdateCollision(vector<CGameObject*> vecGameObjs, float timeFrame)
{

}

void CFlyItemBound::UpdateBox()
{

}